﻿@using Webdiyer.WebControls.Mvc
@model PagedList<NetSurveillance.WebApp.DataServices.Models.User>
@{
    ViewBag.Title = Resources.MenuResource.SystemSetting_AccountManage;
    Layout = "~/Views/Shared/_SystemConfigLayout.cshtml";
    ViewBag.CurrentMiddleMenu = 7;
    ViewBag.CurrentMainMenu = 5;
}
<div style="text-align: right;padding-right: 5px;margin-bottom: 10px;">
    <dl class="filemanage_right_dl">
        <dd id="btnAddEntry"><a href="@Url.Action("SaveAccount")">@Resources.Resource.Button_AddAccount</a></dd>      
    </dl>
</div>
<table cellpadding="0" cellspacing="0" class="file_manage_tab" border="0" id="tbAccount">
    <thead>
        <tr>
            <th>用户ID</th>
            <th>用户名</th>
            <th>用户密码</th>
            <th>真实姓名</th>
            <th>Email</th>
            <th>手机号码</th>
            <th>创建时间</th>
            <th style="width: 180px;">&nbsp;&nbsp;</th>
        </tr>
    </thead>
    <tbody>
        @foreach (var user in Model)
        {
            <tr data-entryId="@user.Id" class="chk_showdialog_td_center">
                <td>@user.Id</td>
                <td>@user.UserName</td>
                <td>@user.Password</td>
                <td>@user.RealName</td>
                <td>@user.Email</td>
                <td>@user.Phone</td>
                <td>@user.CreatedTime.ToShortDateString()</td>
                <td style="text-align: center;">
                    <input class="btn_set" type="button" value="@Resources.Resource.Button_Alter" onclick="alterAccount(@user.Id);"/>
                    <input class="btn_set" type="button" value="@Resources.Resource.Button_Delete" onclick="deleteAccount(@user.Id);"/>
                </td>
            </tr>
        }
    </tbody>
</table>
@Html.Pager(Model, new PagerOptions
{
    PageIndexParameterName = "pageIndex",
    CurrentPagerItemWrapperFormatString = "<span class=\"cpb\">{0}</span>",
    NumericPagerItemWrapperFormatString = "<span class=\"item\">{0}</span>",
    CssClass = "pages",
    SeparatorHtml = ""
})

@section javascript
{
    <script type="text/javascript">

        $(function(){
            pageResize();
            $(window).bind('resize', pageResize);
        });
        
        function pageResize(){
            var arrayPageSize = getPageSize();
            var myHeight = arrayPageSize[3];
            $("#middle_right_body").height(myHeight-40-74);
        }

        function alterAccount(accountId) {
            if(!accountId) return;
            window.location.href = '@Url.Action("SaveAccount")' + '?accountId=' + accountId;
        }

        function deleteAccount(accountId) {
            if(!accountId || !window.confirm('@Resources.MessageResource.Delete_Confirm')) return;
            $.showLoading('Deleting now,please wait');
            $.ajax({
                url: '@Url.Action("DeleteAccount")',
                type: 'post',
                dataType: 'json',
                data: { accountId: accountId },
                success: function(result) {
                    if (result.Success) {
                        $('#tbAccount tr[data-entryId=' + accountId + ']').remove();
                    } else {
                        alert(result.Message);
                    }
                    $.hideLoading();
                }
            });
        }
    </script>
}
